#include "ranklogin.h"
#include "ui_ranklogin.h"
#include "mainwindow.h"
#include "startwindow.h"

#include <QPainter>
#include <QMouseEvent>
#include<QListWidgetItem>
#include<QTextStream>
#include <QDebug>
#include <QVector>
#include <QMessageBox>

RankLogin::RankLogin(int sc, QWidget *parent) :
    QWidget(parent),score(sc),
    ui(new Ui::RankLogin)
{
    ui->setupUi(this);

    //去窗口边框
    setWindowFlags(Qt::FramelessWindowHint | windowFlags());

    //把窗口背景设置为透明;
    setAttribute(Qt::WA_TranslucentBackground);

    sf = new MainWindow();
    sf2 = new startwindow();

    //发送者是game界面sf对象，信号是SignalSetRecord(int)
    connect(sf,SIGNAL(SignalSetRecord(QString)),this,SLOT(processInforFromMainwidow(QString)));
}

RankLogin::~RankLogin()
{
    delete ui;
}

void RankLogin::setDistance(int dis)
{
    distance=dis;
    ui->lcdNumber->display(dis);
}

void RankLogin::on_finishButton_clicked()
{
    if(ui->lineEdit->text().isEmpty())
    {
        QMessageBox::warning(this,"Component failed","Your name cannot be empty!");
    }else{
        name = ui->lineEdit->text();

        sf3=new RankDialog();
        sf3->addRecord(score,name);
        sf3->saveRank();

        sf2->show();
        sf3->show();

        close();
    }   
}
